package com.boby.lib_common.util

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import org.json.JSONObject

object JsonUtil {
    inline fun <reified T> fromJson(json: String): T {
        val gson = Gson()
        return gson.fromJson(json, object : TypeToken<T>() {}.type)
    }

//    fun <T>fromJson(json: String): T {
//        val gson = Gson()
//        return gson.fromJson(json, object : TypeToken<T>() {}.type)
//    }

    fun <T> fromJson(json: String,Class:Class<T>): T {
        val gson = Gson()
        return gson.fromJson(json, Class)
    }
    fun toJson(obj: Any): String {
        val gson = Gson()
        return gson.toJson(obj)
    }
}